Linux 正则表达式 | 您所在的位置:网站首页 › url 正则 › Linux 正则表达式 |
正则表达式有什么用?最基本的爬虫会用到,正则表达式简单来说就是匹配字符串的 比如:你匹配所有图片的链接地址 比如、abc/def URL:在WWW上,每一信息资源都有统一的且在网上的地址,该地址就叫URL(Uniform Resource Locator,统一资源定位器),它是WWW的统一资源定位标志,就是指网络地址 正则表达式和通配符不一样! 通配符只能匹配文件名 正则表达式的功能十分强大,可以匹配字符串 1.正则表达式 正则表达式是处理字符串的方法,他是以行为单位来进行字符串处 理的行为,通过一些特殊符号的辅助,可以让使用者轻易的达到 搜 索/删除/取代某特定字符串的处理程序。 正则表达是一种表示方法,工具程序支持这种表示方法,则可以用 正则表达式来进行字符串的处理。例如:vi、grep(搜索以abc开头的行)、awk、sed等用途:分析日志、简单的垃圾邮件过滤(比如广告)、软件(系统)配置等等 规范: 正则表达式拥有不同的规范,POSIX规范,Perl规范,Python规范等(perl规范和Python其实无太大差别), Shell中的grep、egrep都使用POSIX规范。POSIX规范包括: 1.基本的正则表达式 POSIX字符:POSIX字符类是一个形如[:...:]的特殊元序列,他可以用于匹配特定的字符范围。 搜索指定字符串(以grep命令,搜索regular.txt文件为例) "Open Source" is a good mechanism to develop programs. apple is my favorite food. Football game is not use feet only. this dress doesn't fit me. However, this dress is about $ 3183 dollars. GNU is free air not free beer. Her hair is very beauty. I can't finish the test. Oh! The soup taste good. motorcycle is cheap than car. This window is clear. the symbol '*' is represented as start. Oh! My god! The gd software is a library for drafting programs. You are the best is mean you are the no. 1. The world is the same with "glad". I like dog. google is the best tools for search keyword. goooooogle yes! go! go! Let's go. # I am VBird 建一个regular文件含有字符的搜索 注意这两个匹配的方式:为什么有两个中括号要搞懂 grep –n ‘[^[:lower:]]oo ’ regular.txt grep –n ‘[^[:digit:]]’ regular.txt 指定开始、结尾字符串的搜索 (以grep命令,搜索regular.txt文件为例) 一定要区分^和中括号里面的^区分开,一个代表行首,一个代表取反含 有 任 意 、 重 复 字 符 的 字 符 串 搜 索 ( 以 grep 命 令 , 搜 索 regular.txt文件为例) . :一定有一个任意字符 * :重复前一个字符,0到多次 grep –n ‘o*’ regular.txt grep –n ‘ oo*’ regular.txt 2 . 扩 展 的 正 则 表 达 式 |
CopyRight 2018-2019 实验室设备网 版权所有 |